<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>合同配送</title>
	<link rel="stylesheet" href="css/reset.css">
	<link rel="stylesheet" href="css/product.css">
	<link rel="stylesheet" href="css/select.css">
	<style>
		.main-bg1{
			padding-bottom: 0px;
		}
		.content-table-two{
			width: 1080px;
		}
		.content-table-two tbody tr td {
    		max-width: 300px;
    		min-width: 20px; 
    	}
		.content-table-two tbody tr td{
			width: 30px;
			padding-left: 12px;
			padding-right: 12px;
		}
		.content-table-two tbody tr td:first-child{
			width:20px;
		}
		.content-table-two tbody tr td:nth-child(2){
			width:50px;
		}
		.content-table-two tbody tr td:nth-child(3){
			width:165px;
		}
		.content-table-two tbody tr td:nth-child(4){
			width:70px;
		}
		.content-table-two tbody tr td:nth-child(10){
			width:70px;
		}
		.content-btn {
		    padding-bottom: 5px;
		}
		.content-btn> .btn-style-two{
			float: right;
			margin-left: 8px;
		}
		.export-btn {
		    float: left;
		    margin-top: 0px;
			min-width:50px;
		    margin-right: 12px;
		}
	</style>
</head>
<body>
	<div class="main-content">
		<div class="main-bg1">
			<div class="product-content clearfix">
				<div class="product-child">
					<div class="product-child-content">
						<p class="content-title matop">合同回寄</p>
						<div class="content-form">
							<form id = "seachContractDetailForm">
								<!-- <input type = "hidden" value = "3" name = "status" /> -->
								<ul>
									<li>
										<span class="text-name">项目名称：</span><input type="text" name = "projectname">
									</li>
									<li>
										<span class="text-name">部门名称：</span><input type="text" name = "department">
									</li>
									<li>
										<span class="text-name">客户名称：</span><input type="text" name = "custname">
									</li>
									<li>
										<span class="text-name">合同状态：</span>
										<select class="multiselect" id="single" name = "status">
											<option value="0">已入库</option>
											<option value="1">配送中</option>
											<option value="2">已签收</option>
											<option value="3">已分发</option>
											<option value="4">已回寄</option>
											<option value="5">已入档</option>
											<option value="6">已作废</option>
											<option value="7">调配中</option>
											<option value="8">已调配</option>
											<option value="9">退回中</option>
											<option value="10">已退回</option>
											<option value="11">已经配送认购书</option>
											<option value="12">认购书已签收</option>
										</select>
									</li>
									<li>
										<button class="btn-style-two" id = "seachContractDetail" onclick = "return false">搜索</button>
										<i class="btn-operation maleft20">重置</i>
									</li>
								</ul>
							</form>
						</div>
						<div class="content-list">
							<div class="info-list">
								<div class="content-btn">
									<i onclick = "hthj()" class="export-btn clearfix">合同回寄</i>
								</div>
								<table class="content-table-two" bindClick = "seachContractDetail" bindForm = "seachContractDetailForm" datatable = "true" cellspacing="0" cellpadding="0" dataAction = "/contractDetail/findList">
									<tbody style = "display:none;">
										<th title = "项目编号" name = "projectcode" type = "string"></th>
										<th title = "项目名称" name = "projectname" type = "string"></th>
										<th title = "部门名称" name = "department" type = "string"></th>
										<th title = "回寄快递单号" name = "returntracknumber" type = "string"></th>
										<th title = "合同状态" name = "status" type = "string"></th>
										<th title = "客户编号" name = "custcode" type = "string"></th>
										<th title = "客户名称" name = "custname" type = "string"></th>
										<th title = "理顾姓名" name = "isname" type = "string"></th>
										<th title = "分发时间" name = "issuedate" type = "string"></th> 
										<th title = "预约金额" name = "appoint.balance" type = "Integer"></th>
										<th title = "预约时间" name = "appoint.reserveDate" type = "string"></th>
										<th title = "预约状态" name = "appoint.reserveStatus" type = "string"></th>
										<th title = "排队成功时间" name = "appoint.reservationSuccessDate" type = "string"></th>
										<th title = "倒账金额" name = "appoint.transfercash" type = "Integer"></th>
										<th title = "备注" name = "remark" type = "string"></th>
									</tbody>
								</table>
							</div>
						</div>
					</div>	
				</div>
			</div>
		</div>
	</div>
	<script src="js/jquery-3.2.1.min.js"></script>
	<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
	<script src="js/select.jquery.js"></script>
	<script type="text/javascript" src = "js/util.js"></script>
	<script type="text/javascript" src = "js/table.js"></script>
	<script>
		$('.multiselect').multiselect({setMaxOptionNum:4,selectedHtmlValue:''});
		$('#single').multiselect({multiple:false,setWidth: 140+'px'});
		function trackingResults(){
		  	parent.layer.open({
			      type: 2,
			      title: '跟踪结果',
			      shadeClose: true,
			      shade: 0.2,
			      maxmin: true, //开启最大化最小化按钮
			      area: ['870px', '400px'],
			      content: 'view/trackingResults.html'
			});
		}
		function seeApply(){
			  parent.layer.open({
		      type: 2,
		      title: '查看意向申请',
		      shadeClose: true,
		      shade: 0.2,
		      maxmin: true, //开启最大化最小化按钮
		      area: ['870px', '60%'],
		      content: 'view/seeApply.html'
			});
		}
		function ps(){
			var data = $("table").getCheckData();
			if(data.length < 1){
				parent.layer.msg("请选择记录。");
				return;
			}
			parent.setData(data);
			window.location.href = "addContractdistribution.html";
		}
		function cansel(i){
			var data = $("table").getAllData()[i];
			parent.layer.confirm('是否确认作废纸质合同？', {
				btn: ['确定','取消'] //按钮
			}, function(){
				var param = new FormData();
				param.append("id",data.id);
				param.append("status","6")
				$.ajax({
			        type: 'post',
			        url:baseUrl + "/contractDetail/save",
			        contentType: false,  
			        processData: false, 
			        async: false,
			        data:param
				}).done(function(dt){
					if(dt == 0){
						parent.layer.msg("撤销签收失败!");
					}else{
						parent.layer.msg("撤销合同成功!");
						$("table").ECDATable();
					}
				});
			},function(){
				parent.layer.closeAll();
			});
		}
		function canselfenfa(i){
			var data = $("table").getAllData()[i];
			parent.layer.confirm('是否撤销分发？', {
				btn: ['确定','取消'] //按钮
			}, function(){
				var param = new FormData();
				param.append("id",data.id);
				param.append("appoint.reserveNo",data.appoint.reserveNo);
				param.append("appoint.id",data.appoint.id);
				console.log(data);
				$.ajax({
			        type: 'post',
			        url:baseUrl + "/contractDetail/canselDistribute",
			        contentType: false,  
			        processData: false, 
			        async: false,
			        data:param
				}).done(function(dt){
					if(dt == 0){
						parent.layer.msg("撤销分发失败!");
					}else{
						parent.layer.msg("撤销分发成功!");
						$("table").ECDATable();
					}
				});
			},function(){
				parent.layer.closeAll();
			});
		}
		function hthj(i){
			var data = $("table").getAllData()[i];
			if(!data){
				data = $("table").getCheckData()
			}
			if(data instanceof Array){
    		}else{
    			var d = [];
    			d.push(data);
    			data = d;
    		}
			parent.setData(data);
			window.location.href = "hetonghuiji.html";
		}
		function tableCallBack(my){
			my.find("thead").find("tr").prepend("<td><input type=\"checkbox\"></td>");
			var $tr = my.find("tbody").eq(1).find("tr");
			for(var i = 0 ; i < $tr.length ; i++){
				var html = "<td><input type=\"checkbox\"></td>";
				$($tr[i]).prepend(html);
			}
			my.find("thead").find("input[type='checkbox']").click(function(){
				var $this = $(this);
				my.find("tbody").find("input[type='checkbox']").prop("checked",$this.is(":checked"));
			});
			my.find("thead").find("tr").append("<td>操作</td>");
			var $tr = my.find("tbody").eq(1).find("tr");
			var data = $("table").getAllData();
			for(var i = 0 ; i < $tr.length ; i++){
				var html = "";
				if(data[i].status != "6"){
					html += "<td><i class = \"btn-operation\" onclick = \"cansel(" + i + ")\">合同作废</i>";
				}
				if(data[i].appoint&&data[i].status == "3"){
					html += "<i class = \"btn-operation\" onclick = \"canselfenfa(" + i + ")\">撤回分发</i>";
					html += "<i class = \"btn-operation\" onclick = \"hthj(" + i + ")\" >合同回寄</i></td>"
				}
				$($tr[i]).append(html);
			}
		}
	</script>
</body>
</html>